const express = require('express');
const router = express.Router();
const db = require('../utils/lowdb.js').getDB('category.json');
const mockjs = require('mockjs');

db.defaults(
  mockjs.mock({
    'list|10': [
      {
        id: '@GUID()',
        name: '@CWORD(2, 4)',
        img: '@IMAGE("100x100", "@color")',
      },
    ],
  })
).write();

router.get('/list', (req, res) => {
  const state = db.getState();
  res.json({
    code: 200,
    msg: 'ok',
    data: state.list,
  });
});

module.exports = router;
